jQuery(window).load(function() {
/* Navigation */
	jQuery('#submenu ul.sfmenu').superfish({ 
		delay:       500,								// 0.1 second delay on mouseout 
		animation:   { opacity:'show',height:'show'},	// fade-in and slide-down animation 
		dropShadows: true								// disable drop shadows 
	});	
	

/* Hover block */

	jQuery('.portfolio-box').hover(function(){
			jQuery(this).find('div').animate({opacity:'1'},{queue:false,duration:500});
	}, function(){
			jQuery(this).find('div').animate({opacity:'0'},{queue:false,duration:500});
		});

	
/* equal column	 */
	
	  var biggestHeight = 0;  
    //check each of them  
    jQuery('.equal_height').each(function(){  
        //if the height of the current element is  
        //bigger then the current biggestHeight value  
        if(jQuery(this).height() > biggestHeight){  
            //update the biggestHeight with the  
            //height of the current elements  
            biggestHeight = jQuery(this).height();  
        }  
    });  
    //when checking for biggestHeight is done set that  
    //height to all the elements  
    jQuery('.equal_height').height(biggestHeight);  
    //cài css cho iframe them album/anh
    jQuery(".toggle_button").click(function()
    {
	    toogle();
	});

	function toogle()
    {
        if(jQuery("#secondary").is(":visible"))
        {
            jQuery("#secondary").hide(500,function(){

            jQuery("#toggle_icon").css({'transition-duration': '0.5s','-webkit-transform' : 'rotate(90deg)',
                 '-moz-transform' : 'rotate(90deg)',
                 '-ms-transform' : 'rotate(90deg)',
                 'transform' : 'rotate(90deg)'});
            //jQuery("#primary").css({'transition-duration': '0.5s','-webkit-transition':'margin-left 0.5s','margin-left':'50px' });
            jQuery(".grid_12").css({'transition-duration': '0.5s','-webkit-transition':'margin-left 0.5s','margin-left':'0px','width':'100%'});

            // jQuery(".grid_12").css({'transition-duration': '0.5s','-webkit-transition':'width 0.5s','width':'100%' });
            });
            // var r=jQuery("iframe").width()+100;
            // if (r>1300)
            // else
            //  jQuery("#primary").css({'transition-duration': '0.5s','-webkit-transition':'margin-left 0.5s','margin-left':'150px', });
            SetCookie('Is_SideBar_Showing',0,1);

        }
        else
        {
            jQuery("#secondary").show(500);

            jQuery("#secondary").css({'transition-duration': '0.5s','-webkit-transition':'width 150px','width':'150px' });
            jQuery("#toggle_icon").css({'transition-duration': '0.5s','-webkit-transform' : 'rotate(0deg)',
                 '-moz-transform' : 'rotate(0deg)',
                 '-ms-transform' : 'rotate(0deg)',
                 'transform' : 'rotate(0deg)'});
            //jQuery("#primary").css({'transition-duration': '0.5s','-webkit-transition': 'margin-left 0.5s width 0.5s','margin-left':'50px' });
            jQuery(".grid_12").css({'transition-duration': '0.5s','-webkit-transition':'margin-left 0.5s','margin-left':'130px','width':'auto'});
            // jQuery(".grid_12").css({'width':'auto' });
            SetCookie('Is_SideBar_Showing',1,1);

        }
    }
    function SetCookie(cookieName,cookieValue,nDays) {
         var today = new Date();
         var expire = new Date();
         if (nDays==null || nDays==0) nDays=1;
         expire.setTime(today.getTime() + 3600000*24*nDays);
         document.cookie = cookieName+"="+escape(cookieValue)
                         + ";expires="+expire.toGMTString();
    }
    function ReadCookie(cookieName) {
         var theCookie=" "+document.cookie;
         var ind=theCookie.indexOf(" "+cookieName+"=");
         if (ind==-1) ind=theCookie.indexOf(";"+cookieName+"=");
         if (ind==-1 || cookieName=="") return "";
         var ind1=theCookie.indexOf(";",ind+1);
         if (ind1==-1) ind1=theCookie.length; 
         return unescape(theCookie.substring(ind+cookieName.length+2,ind1));
    }
    if(ReadCookie('Is_SideBar_Showing')==0)
    {
            jQuery("#secondary").hide(500,function(){
                jQuery("#toggle_icon").css({'transition-duration': '0.5s','-webkit-transform' : 'rotate(90deg)',
                 '-moz-transform' : 'rotate(90deg)',
                 '-ms-transform' : 'rotate(90deg)',
                 'transform' : 'rotate(90deg)'});
            //jQuery("#primary").css({'transition-duration': '0.5s','-webkit-transition':'margin-left 0.5s','margin-left':'50px' });
            jQuery(".grid_12").css({'transition-duration': '0.5s','-webkit-transition':'margin-left 0.5s','margin-left':'0px','width':'100%'});

            // jQuery(".grid_12").css({'transition-duration': '0.5s','-webkit-transition':'width 0.5s','width':'100%' });
            });

    }
    else
    {
         jQuery("#secondary").show();

            jQuery("#secondary").css({'width':'150px' });
            jQuery("#toggle_icon").css({
                 '-moz-transform' : 'rotate(0deg)',
                 '-ms-transform' : 'rotate(0deg)',
                 'transform' : 'rotate(0deg)'});
            //jQuery("#primary").css({'transition-duration': '0.5s','-webkit-transition': 'margin-left 0.5s width 0.5s','margin-left':'50px' });
            jQuery(".grid_12").css({'margin-left':'130px','width':'auto'});
    }
});

jQuery(document).ready(function(){
    //tao doi tuong websocket
   // var wsUri = "ws://localhost:9070/server.php";   
   // wsocket = new WebSocket(wsUri); 
    
    //khi ket noi duoc mo
    //khi nhan dc message tu sever
    //    wsocket.onmessage = function(ev) {
    //     var msg = JSON.parse(ev.data); //chuyen chuoi JSON thanh doi tuong JSON
    //     var type = msg.notification_type; //kieu message
    //     var counter=msg.counter;
    //     if(type == 'like') //neu la message cua user
    //     {
    //         jQuery('.comment_counter').css({opacity: 0});
    //         jQuery('.comment_counter').text(counter);
    //         jQuery('.comment_counter').css({top: '-10px'});
    //         jQuery('.comment_counter').animate({top: '-2px', opacity: 1});
    //     }
    //     if(type == 'comment') //neu la message cua he thong
    //     {
    //         jQuery('.like_counter').css({opacity: 0});
    //         jQuery('.like_counter').text(counter);
    //         jQuery('.like_counter').css({top: '-10px'});
    //         jQuery('.like_counter').animate({top: '-2px', opacity: 1});
    //     }
    //      if(type == 'image') //neu la message cua he thong
    //     {
    //         jQuery('.image_counter').css({opacity: 0});
    //         jQuery('.image_counter').text(counter);
    //         jQuery('.image_counter').css({top: '-10px'});
    //         jQuery('.image_counter').animate({top: '-2px', opacity: 1});
    //     }
    //      if(type == 'message') //neu la message cua he thong
    //     {
    //         jQuery('.image_counter').css({opacity: 0});
    //         jQuery('.image_counter').text(counter);
    //         jQuery('.image_counter').css({top: '-10px'});
    //         jQuery('.image_counter').animate({top: '-2px', opacity: 1});
    //     }
    // };
    });